<?php

namespace api\controllers;

use common\components\JwtAuthor;
use yii\rest\ActiveController;

// use yii\rest\ActiveController;

class BaseController extends ActiveController
{
    public $except = []; //不认证的动作
	public $optional = []; //可认证、可不认证的动作
	protected $pageSize = 30; //分页每页条数

	//直接在响应主体内包含分页信息
	public $serializer = [
		'class'              => 'yii\rest\Serializer',
		'collectionEnvelope' => 'items',
	];

    public function actions()
    {
        $action = parent::actions(); 
        unset($action['index']);
        unset($action['create']);
        unset($action['update']);
        unset($action['delete']);
        return $action;
    }

    public function behaviors()
	{
		$behaviors = parent::behaviors();
		unset($behaviors['rateLimiter']); //移除速率限制组件

		//验证方法
		$behaviors['authenticator'] = [
			'class'    => JwtAuthor::class,
			'except'   => $this->except,
			'optional' => $this->optional
		];

        return $behaviors;
	}
}
